package org.zls.client.login;

import org.zls.client.Util;
import org.zls.client.service.ServerService;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class Callback {
	
	public static final class ValidateCallback implements AsyncCallback {
		
		private boolean validated = false;
		
		public void onFailure(Throwable caught) {
			Window
					.alert("ERROR: Failed to authenticate credentials with server.");
		}

		public void onSuccess(Object result) {
			validated = Boolean.parseBoolean(result.toString());
		}
		
		public boolean getValidated() {
			return validated;
		}
	}

	public static final class MystifyCallback implements AsyncCallback {

		private int e;
		private int p;

		public MystifyCallback(int e, int p) {
			this.e = e;
			this.p = p;
		}

		public void onFailure(Throwable caught) {
			Window
					.alert("ERROR: Failed to authenticate credentials with server.");
		}

		public void onSuccess(Object success) {
			long key = Long.parseLong(success.toString());
			ValidateCallback vcallback = new ValidateCallback();
			ServerService.Util.getInstance().verifyCredentials(Util.mystify(e, key), Util.mystify(p, key), vcallback);
		}
	}
}
